/*
 * timer_ms.h
 *
 *  Created on: 13 May 2015
 *      Author: yiqi.pan
 */

#ifndef SRC_TIMER_MS_H_
#define SRC_TIMER_MS_H_


enum
{
    GENERIC_TIMER = 0,
	BT_TIMER,
	BUTTON_TIMER1,
	BUTTON_TIMER2,
    TIMER_MS_COUNT
} ;

/**
 * \brief Timeout identifier
 *
 * Index for timeout to use. Limited by max value configured with \ref
 * CONFIG_TC_TIMEOUT_COUNT.
 */
typedef uint8_t timer_id_t;


extern void timer_ms_interrupt(void);
/**
 * \brief Initialize TC timeout
 *
 * Initializes Timer/Counter for desired tick rate and starts it.
 */
void timer_ms_init(void);

/**
 * \brief Start singleshot timeout
 *
 * \param id \ref tc_timeout_id_t
 * \param timeout Timeout in number of ticks
 */
void timer_ms_start_singleshot(timer_id_t id, uint16_t timeout);

/**
 * \brief Start periodic timeout
 *
 * \param id \ref tc_timeout_id_t
 * \param period Time period in number of ticks
 */
void timer_ms_start_periodic(timer_id_t id, uint16_t period);

/**
 * \brief Start periodic timeout with a specific start timeout
 *
 * \param id \ref tc_timeout_id_t
 * \param period Time period in number of ticks
 * \param start_offset Time to first timeout in number of ticks
 */
void timer_ms_start_offset(timer_id_t id, uint16_t period,
		uint16_t start_offset);

/**
 * \brief Test and clear expired flag for running timeout
 *
 * \param id \ref tc_timeout_id_t
 * \retval true Timer have expired; clearing expired flag
 * \retval false Timer still running
 */
bool timer_ms_test_and_clear_expired(timer_id_t id);

/**
 * \brief Stop running timeout
 *
 * \param id \ref tc_timeout_id_t
 */
void timer_ms_disactivate(timer_id_t id);

/**
 * \brief Test is timer is running
 *
 * \param id \ref tc_timeout_id_t
 */
bool is_active_timer_ms(timer_id_t id);

void timer_ms_stop(void);



#endif /* SRC_TIMER_MS_H_ */
